<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>新建会议</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../static/layui-v2.6.8/layui/css/layui.css">

    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>

<body>

    <form class="layui-form" action="" lay-filter="example">
        <div class="layui-form-item"></div>
        <input type="hidden" name="rid" lay-verify="required" value="{{rid}}" placeholder="会议主题" autocomplete="off"
            class="layui-input">
        <div id="test7" class="demo-transfer demo-tree-more">
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <div></div>
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1"
                    lay-demotransferactive="getData">立即提交</button>
                <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-setval">重置</button>


            </div>
        </div>


    </form>

    <script src="../../../static/layui-v2.6.8/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

    <script>
        layui.use(['form', 'layedit', 'laydate',], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , transfer = layui.transfer
                , util = layui.util
                , $ = layui.jquery;

            var data1 = [
                { "value": "1", "title": "李白" }
                , { "value": "2", "title": "杜甫" }
                , { "value": "3", "title": "苏轼" }

            ]

            //限定可选日期--不可在当前时间之后
            var ins22 = laydate.render({
                //更改为当前时间之后

                elem: '#test-limit1'
                , min: 0
                , max: 15

            });

            //限定可选时间--不可在当前时间之前
            laydate.render({
                //更改为
                elem: '#test-limit3'
                , type: 'time'
                , min: '06:30:00'
                , max: '21:30:00'
                , btns: ['clear', 'confirm']
            });

            laydate.render({
                //更改为
                elem: '#test-limit4'
                , type: 'time'
                , min: '09:30:00'
                , max: '17:30:00'
                , btns: ['clear', 'confirm']
            });

            //验证提交规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
                , pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });

            layui.$(function () {
                layui.$.ajax({
                    type: 'get',
                    url: 'get_permission',
                    success: function (res) {
                        if (res.code == 200) {
                            personnel = res.data
                            console.log(personnel)
                            transfer.render({
                                elem: '#test7'
                                , data: personnel
                                , id: 'key123' //定义唯一索引
                                , title: ['菜单列表', '可选权限']
                                , showSearch: true
                                , value: {{ list_per }}
                    })
            }
                    }
                })
            })
        var meetData = {}
        form.on('submit(demo1)', function (data) {
            console.log(JSON.stringify(data.field))
            //此段代码可以获取提交的数据
            var $ = layui.$
            meetData['meet_content'] = data.field
            //ajax 提交
            $.ajax({
                type: "POST",
                dataType: "text",
                url: "add_permission",//url
                data: JSON.stringify(meetData),  //表单数据
                success: function (data) {
                    console.log(data)
                    layer.msg('添加成功，1秒后自动关闭该窗口');
                    //延迟1秒执行，目的是让用户看到提示
                    setTimeout(function () {
                        //1、先得到当前iframe层（弹出层）的索引  ///2、提交成功关闭弹出层窗口
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }, 1 * 1000);

                },
                error: function () {
                }
            });
            //阻止页面跳转
            return false;
        });

        util.event('lay-demoTransferActive', {
            getData: function (othis) {

                var getData = transfer.getData('key123'); //获取右侧数据
                console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
                console.log(getData[0].value)
                console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
                var personnels = {}
                console.log('执行了11')
                //处理数据交
                layui.each(getData, function (index) {
                    console.log('------>>>执行了33', getData[index].title)
                    personnels[getData[index].value] = getData[index].title
                    console.log('------------>>执行了44', personnels)
                })

                meetData['meet_personnel'] = personnels
                console.log('----------------->执行55', JSON.stringify(meetData))
                //   console.log('--------->执行了55',JSON.stringify(meetData))

            }

        });
        });

    </script>

</body>

</html>